﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Help;
using Model;
namespace BLLA
{
    public partial class Order_DayReport_Mer_T : BaseBLL<Model.Order_DayReport_Mer_T>, IBLL.IOrder_DayReport_Mer_TBLL
    {
        ObjectSerialize os = new ObjectSerialize();
        DataResult result = new DataResult();


        /// <summary>
        /// 生成商户总日结表
        /// </summary>
        /// <param name="MerID"></param>
        /// <param name="YZM"></param>
        /// <param name="RETID"></param>
        /// <returns></returns>
        public void DayReport_Mer_T()
        {

            string time = DateTime.Now.ToString("yyyyMMdd");//当天时间
            List<Model.Order_Mer_T> mo = new List<Model.Order_Mer_T>();
            List<Model.Order_Form_T> AllForm = new List<Model.Order_Form_T>();
            mo = base.DBSession.IOrder_Mer_TDAL.GetListBy(u => u.MerState == 1);//获取所有商户
            foreach (var it in mo)//遍历商户
            {

                List<Model.Order_DayReport_Mer_T> DayReport = new List<Model.Order_DayReport_Mer_T>();//商户总结
                AllForm = base.DBSession.IOrder_Form_TDAL.GetListBy("SELECT * FROM  Order_Form_T where FormTime>'" + time + "000000" + "' and FormTime<'" + time + "235959" + "' and FormMerID='" + it.MerID + "'and FormState='" + 1 + "'");//获取商户一天有效的订单
                //AllForm = base.DBSession.IOrder_Form_TDAL.GetListBy(u => u.FormState == 1 || u.FormMerID == it.MerID);
                if (AllForm.Count != 0)
                {
                    Model.Order_DayReport_Mer_T DayRe = new Model.Order_DayReport_Mer_T();
                    foreach (var item in AllForm)//遍历订单
                    {
                        string[] str = item.FormDishesMon.Split(',');//原价集合变字符串数组
                        string[] DishesNun = item.FormDishesNun.Split(',');//菜品数量
                        for (int i = 0; i < str.Length; i++)
                        {

                            DayRe.MerOriginal += int.Parse(str[i]) * int.Parse(DishesNun[i]);//菜品原价
                        }
                        DayRe.MerReceivables += item.FormAllMon;//应收
                        if (item.FormPreMon != null)
                        {
                            DayRe.MerDiscount += (int)item.FormPreMon;// 优惠
                        }
                        DayRe.MerActual += item.FormPayMon;//实收

                    }
                    DayRe.MerID = it.MerID;//商户id
                    DayRe.DayReportDate = time;//日期8位
                    DayReport.Add(DayRe);
                    base.DBSession.IOrder_DayReport_Mer_TDAL.Add(DayReport);
                }

            }
        }

        /// <summary>
        /// 生成商户分类日结表
        /// </summary>
        public void DayReport_DishesType_T()
        {

            //string time = DateTime.Now.ToString("yyyyMMdd");//当天时间
            //List<Model.Order_Mer_T> mo = new List<Model.Order_Mer_T>();//商户
            //List<Model.Order_DishesType_T> DishesT = new List<Model.Order_DishesType_T>();//菜品分类
            //mo = base.DBSession.IOrder_Mer_TDAL.GetListBy(u => u.MerState == 1);//获取所有商户
            //if (mo.Count != 0)
            //{
            //    foreach (var item in mo)//轮询商户，并查询所有商户下的订单
            //    {
            //        List<Model.Order_DayReport_DishesType_T> DishesType = new List<Model.Order_DayReport_DishesType_T>();//商户分类日结
            //        DishesT = base.DBSession.IOrder_DishesType_TDAL.GetListBy(u => u.MerID == item.MerID);//商户下所有菜品分类来源

            //        List<Model.Order_DayReport_Mer_T> DayReport = base.DBSession.IOrder_DayReport_Mer_TDAL.GetListBy(u => u.MerID == item.MerID & u.DayReportDate == time);//一个商户一天只能有一条商户总日结记录
            //        if (DayReport.Count != 0)
            //        {
            //            List<Model.NewDishes_T> NewDishes = new List<Model.NewDishes_T>();//结合
            //            List<Model.Order_Form_T> AllForm = base.DBSession.IOrder_Form_TDAL.GetListBy(u => u.FormMerID == item.MerID & u.FormTime.Substring(0, 8) == time & u.FormState == 1);//在商户总日结的当天时间的所有订单
            //            //AllForm = base.DBSession.IOrder_Form_TDAL.GetListBy(u => u.FormMerID == item.MerID & u.FormState == 1);//在商户总日结的当天时间的所有订单--测试
            //            if (AllForm.Count != 0)
            //            {
            //                //轮询订单并获取菜品信息(菜品分类id，赋值原价=原价*数量，赋值实价=实价*数量)，用List集合DishesType菜品信息承载
            //                foreach (var st in AllForm)
            //                {

            //                    string[] form = st.FormDishesID.Split(',');//菜品id
            //                    string[] DishesMon = st.FormDishesMon.Split(',');//菜品原价
            //                    string[] DishesNun = st.FormDishesNun.Split(',');//菜品数量
            //                    //每个菜品id都放入相应的类中
            //                    for (int i = 0; i < form.Length; i++)//轮询菜品id集合，获取每条订单中菜品id的原件*数量，实价*数量
            //                    {
            //                        Model.NewDishes_T NewDishes_T = new Model.NewDishes_T();//新定义类（总日结id，原价和=原价*数量，实价和。。。，分类id）
            //                        string DisId = form[i];
            //                        Model.Order_Dishes_T Order_Dishes = base.DBSession.IOrder_Dishes_TDAL.GetListBy(u => u.DishesID == DisId).First();//一个菜品id一条菜品信息查菜品实际价格菜品分类id
            //                        //分类id
            //                        NewDishes_T.DishesTypeID = Order_Dishes.DishesTypeID;
            //                        //赋值原价=原价*数量
            //                        NewDishes_T.TypeOriginal = int.Parse(DishesMon[i].ToString()) * int.Parse(DishesNun[i]);
            //                        //Dishes_T.DishesMon = num;//赋值实价=实价*数量
            //                        NewDishes_T.TypeActual = (int.Parse(Order_Dishes.DishesPay.ToString()) * int.Parse(DishesNun[i]));
            //                        NewDishes_T.MerDayReportID = DayReport[0].MerDayReportID;
            //                        NewDishes.Add(NewDishes_T);//把所有菜品分类，得菜品信息（菜品分类id、实际价格）

            //                    }
            //                }

            //                foreach (var mer in DishesT)//轮询商户菜品分类,多少类，循环DishesType
            //                {
            //                    Model.Order_DayReport_DishesType_T dic = new Model.Order_DayReport_DishesType_T();
            //                    dic.MerDayReportID = DayReport[0].MerDayReportID;//总日结id
            //                    for (int j = 0; j < NewDishes.Count; j++)//轮询菜品信息Dishes集合
            //                    {
            //                        if (mer.DishesTypeID == NewDishes[j].DishesTypeID)//判断菜品分类id是否相等
            //                        {
            //                            dic.TypeDayReportID = DayReport[0].MerDayReportID;//总日结id
            //                            dic.DishesTypeID = mer.DishesTypeID;//菜品分类中菜品分类id等日结表分类id
            //                            dic.TypeOriginal += NewDishes[j].TypeOriginal;//同类原价总和
            //                            dic.TypeActual += NewDishes[j].TypeActual;//实收总和

            //                        }
            //                    }

            //                    if (dic.DishesTypeID != null & dic.DishesTypeID != "")
            //                    {
            //                        DishesType.Add(dic);
            //                    }


            //                }
            //                base.DBSession.IOrder_DayReport_DishesType_TDAL.Add(DishesType);
            //            }
            //        }
            //    }
            //}

        }

        /// <summary>
        /// 生成商户日记表:到设置系统时间，每天生成一次
        /// </summary>
        public void DayReport_Dishes_T()
        {
            string time = DateTime.Now.ToString("yyyyMMdd");//当天时间
            List<Model.Order_Mer_T> mer = new List<Model.Order_Mer_T>();//商户
            List<Model.Order_Form_T> AllForm = new List<Model.Order_Form_T>();//订单
            //List<Model.Order_DishesType_T> DishesT = new List<Model.Order_DishesType_T>();//菜品分类
            List<Model.Order_DayReport_DishesType_T> DishesType = new List<Model.Order_DayReport_DishesType_T>();//商户分类日结

            mer = base.DBSession.IOrder_Mer_TDAL.GetListBy(u => u.MerState == 1);//获取所有商户

            List<Model.NewDishes_T> NewDishes = new List<NewDishes_T>();
            foreach (var m in mer)
            {
                #region
                AllForm = base.DBSession.IOrder_Form_TDAL.GetListBy(u => u.FormMerID == m.MerID & u.FormTime.Substring(0, 8) == time & u.FormState == 1);//在商户总日结的当天时间的所有订单
                //AllForm = base.DBSession.IOrder_Form_TDAL.GetListBy(u => u.FormMerID == m.MerID & u.FormState == 1);//在商户总日结的当天时间的所有订单--测试
                if (AllForm.Count != 0)
                {
                    List<Model.Order_DayReport_Mer_T> DayReport = base.DBSession.IOrder_DayReport_Mer_TDAL.GetListBy(u => u.MerID == m.MerID & u.DayReportDate == time);//
                    if (DayReport.Count != 0)
                    {
                        int RB = DayReport[0].MerDayReportID;
                        //轮询订单并获取菜品信息(原价、单价=实价，用List集合DishesType菜品信息承载
                        foreach (var st in AllForm)
                        {
                            string[] form = st.FormDishesID.Split(',');//菜品id
                            string[] DishesMon = st.FormDishesMon.Split(',');//菜品原价
                            string[] DishesNun = st.FormDishesNun.Split(',');//菜品数量
                            #region
                            for (int i = 0; i < form.Length; i++)//轮询菜品id集合，获取每条订单中菜品id的原件*数量，实价*数量,分类
                            {
                                Model.NewDishes_T NewDishes_T = new NewDishes_T();
                                string DisId = form[i];
                                Model.Order_Dishes_T Order_Dishes = base.DBSession.IOrder_Dishes_TDAL.GetListBy(u => u.DishesID == DisId).First();//一个菜品id一条菜品信息查菜品实际价格菜品分类id
                                Model.Order_DayReport_DishesType_T TypeDayReport = base.DBSession.IOrder_DayReport_DishesType_TDAL.GetListBy(u => u.DishesTypeID == Order_Dishes.DishesTypeID & u.MerDayReportID == RB).First();//获取分类日结id
                                NewDishes_T.TypeDayReportID = TypeDayReport.TypeDayReportID;//
                                NewDishes_T.DishesID = Order_Dishes.DishesID;//菜品id
                                NewDishes_T.Count = int.Parse(DishesNun[i]);//数量
                                NewDishes_T.DishesMon = int.Parse(Order_Dishes.DishesMon.ToString());//菜品原价
                                NewDishes_T.DishesPay = int.Parse(Order_Dishes.DishesPay.ToString());//实价
                                //原价金额=原价*数量
                                NewDishes_T.TypeOriginal = int.Parse(Order_Dishes.DishesMon.ToString()) * int.Parse(DishesNun[i]);
                                //实收=实价*数量
                                NewDishes_T.TypeActual = (int.Parse(Order_Dishes.DishesPay.ToString()) * int.Parse(DishesNun[i]));
                                NewDishes.Add(NewDishes_T);//把所有菜品分类，得菜品信息（菜品分类id、实际价格）

                            }
                            #endregion
                        }
                        List<Model.Order_DayReport_Dishes_T> Day_Dishes = new List<Model.Order_DayReport_Dishes_T>();//日结集合
                        List<Model.Order_Dishes_T> odt = base.DBSession.IOrder_Dishes_TDAL.GetListBy(u => u.MerID == m.MerID & u.DishesTypeState == 1);
                        foreach (var newd in odt)//轮询商户菜品信息,多少类，循环NewDishes
                        {

                            Model.Order_DayReport_Dishes_T DayReport_Dishes = new Model.Order_DayReport_Dishes_T();//日结
                            for (int j = 0; j < NewDishes.Count; j++)//轮询NewDishes集合，把相同菜品id所有的记录统计出一条
                            {
                                if (newd.DishesID == NewDishes[j].DishesID)
                                {
                                    DayReport_Dishes.DishesID = newd.DishesID;//id
                                    DayReport_Dishes.TypeDayReportID = NewDishes[j].TypeDayReportID;//日结分类id
                                    DayReport_Dishes.DishesCount += NewDishes[j].Count;//数量
                                    DayReport_Dishes.DishesMon = NewDishes[j].DishesMon;//原价
                                    DayReport_Dishes.DishesPay = NewDishes[j].DishesPay;//实价
                                    DayReport_Dishes.DishesOriginal += NewDishes[j].TypeOriginal;//原价收
                                    DayReport_Dishes.DishesActual += NewDishes[j].TypeActual;//实价收
                                }
                            }
                            if (DayReport_Dishes.DishesID != null & DayReport_Dishes.DishesID != "")//判断是否有销量，菜品ID是否被赋值
                            {
                                Day_Dishes.Add(DayReport_Dishes);//保存

                            }
                        }
                        base.DBSession.IOrder_DayReport_Dishes_TDAL.Add(Day_Dishes);

                    }
                }
                #endregion
            }
        }



        /// <summary>商户菜品分类日结表
        ///根据商户id及该商户在时间段内查询营业流水
        /// </summary>
        /// <param name="MerID"></param>
        /// <param name="TimeS">开始时间</param>
        ///  <param name="TimeE">结束时间</param>
        ///  <param name="YZM"></param>
        /// <param name="RETID"></param>
        /// <returns></returns>
        public string GetDishesType_table(string MerID, string TimeS, string TimeE, string YZM, int RETID)
        {

            #region 匹配验证码
            if (YZM != Help.ALL_DataV.YZM)
            {
                result.BS = "-88";
                result.Msg = "验证码错误！";
                return os.StringOfObject(result, RETID);
            }
            #endregion

            //List<Model.View_Order_DayReport> DayReport = new List<Model.View_Order_DayReport>();
            //List<Model.View_Order_DayReport> DayReps = new List<Model.View_Order_DayReport>();
            ////Model.View_Order_DayReport 
            //List<Model.Order_DishesType_T> DishesT = new List<Model.Order_DishesType_T>();
            //try
            //{
            //    DishesT = base.DBSession.IOrder_DishesType_TDAL.GetListBy(u => u.MerID == MerID);//获取分类
            //    int S = int.Parse(TimeS.Substring(0, 8));
            //    int E = int.Parse(TimeE.Substring(0, 8));
            //    StringBuilder sql = new StringBuilder();
            //    sql.Append("SELECT * FROM  View_Order_DayReport where MerID='" + MerID + "'");
            //    if (S != null & S != 0)
            //    {
            //        sql.Append(" and DayReportDate  >= '" + S + "' ");  //开始时间的总日结
            //    }
            //    if (E != null & E != 0)
            //    {
            //        sql.Append(" and DayReportDate  <= '" + E + "' ");//结束时间的总日结
            //    }
            //    DayReport = base.DBSession.IView_Order_DayReportDAL.GetListBy(sql.ToString());
            //    foreach (var f in DishesT)//类循环
            //    {
            //        Model.View_Order_DayReport Type = new Model.View_Order_DayReport();
            //        for (int i = 0; i < DayReport.Count; i++)
            //        {
            //            if (f.DishesTypeID == DayReport[i].DishesTypeID)
            //            {
            //                Type.MerID = f.MerID;
            //                Type.DishesTypeID = f.DishesTypeID;
            //                Type.DishesTypeName = f.DishesTypeName;
            //                Type.TypeActual += DayReport[i].TypeActual;//实价和
            //                Type.TypeOriginal += DayReport[i].TypeOriginal;//原价和
            //                Type.MerDayReportID = DayReport[i].MerDayReportID;
            //                Type.TypeDayReportID = DayReport[i].TypeDayReportID;
            //                Type.MerName = DayReport[i].MerName;
            //            }
            //        }
            //        if (Type.DishesTypeID != null & Type.DishesTypeID != "")
            //        {
            //            DayReps.Add(Type);
            //        }

            //    }
            //    if (DayReps != null && DayReps.Count != 0)
            //    {
            //        result.BS = "1";
            //        result.Msg = "查询成功";
            //        result.total = DayReps.Count;
            //        result.rows = DayReps;
            //    }
            //    else
            //    {
            //        result.BS = "0";
            //        result.Msg = "查询不到数据";
            //    }
                return os.StringOfObject(result, RETID); ;
            
        }


        /// <summary>
        /// 获取日结营业统计报表
        /// </summary>
        /// <param name="MerID">商户ID</param>
        /// <param name="Uer">用户标识(一般用户：user;单位用户：org;空为全部)</param>
        /// <param name="TimeS">yyyyMMdd</param>
        /// <param name="TimeE">yyyyMMdd</param>
        /// <param name="YZM">验证码</param>
        /// <param name="RETID">数据格式（1：json；2：xml）</param>
        /// <returns></returns>
        public string GetDayReport_Dishes(string MerID, string Uer, string TimeS, string TimeE, string YZM, int RETID)
        {
            return null;
            #region 匹配验证码
            if (YZM != Help.ALL_DataV.YZM)
            {
                result.BS = "-88";
                result.Msg = "验证码错误！";
                return os.StringOfObject(result, RETID);
            }
            #endregion

            //#region 业务层
            //List<Model.Allreport_T> list = new List<Allreport_T>();
            //List<Model.View_Order_DayReport> mo = new List<Model.View_Order_DayReport>();
            //List<Model.Order_Dishes_T> Dis = new List<Model.Order_Dishes_T>();//菜品信息，商户有多少个菜品id
            //List<Model.Order_Form_T> AllForm = new List<Model.Order_Form_T>();
            //try
            //{

            //    StringBuilder sql = new StringBuilder();
            //    sql.Append("SELECT * FROM  Order_Form_T  where   FormState=1");
            //    if (MerID != null & MerID != "")
            //    {
            //        sql.Append(" and FormMerID = '" + MerID + "'");

            //    }
            //    if (TimeS == TimeE & TimeS != "")
            //    {
            //        sql.Append(" and FormTime >= '" + TimeS + "000000" + "' " + " and FormTime <= '" + TimeS + "235959" + "' ");
            //    }
            //    else
            //    {
            //        if (TimeS != "")
            //        {
            //            sql.Append(" and FormTime >= '" + TimeS + "000000" + "' ");
            //        }
            //        if (TimeE != "")
            //        {
            //            sql.Append(" and FormTime <= '" + TimeE + "235959" + "' ");
            //        }
            //    }
            //    if (Uer != null & Uer != "")
            //    {
            //        if (Uer == "org")
            //        {
            //            sql.Append(" and FormPayType =" + 3);
            //        }
            //        else
            //        {
            //            sql.Append(" and FormPayType != " + 3);
            //        }
            //    }
            //    AllForm = base.DBSession.IOrder_Form_TDAL.GetListBy(sql.ToString());
            //    List<Model.Order_Form_T> Forms = new List<Model.Order_Form_T>();
            //    List<Model.NewDishes_T> NewDishes = new List<Model.NewDishes_T>();
            //    List<Model.Order_Dishes_T> tongji = new List<Model.Order_Dishes_T>();
            //    #region
            //    if (AllForm.Count != 0)
            //    {
            //        foreach (var st in AllForm)//轮询订单
            //        {
            //            string[] form = st.FormDishesID.Split(',');//菜品id
            //            string[] DishesMon = st.FormDishesMon.Split(',');//菜品实际支付价集合
            //            string[] DishesNun = st.FormDishesNun.Split(',');//菜品数量

            //            for (int i = 0; i < form.Length; i++)//轮询一条订单的菜品id集合，获取每条订单中菜品id的原件*数量，实价*数量,分类
            //            {
            //                Model.NewDishes_T NewDishes_T = new Model.NewDishes_T();
            //                string DisId = form[i];
            //                Model.Order_Dishes_T Order_Dishes = base.DBSession.IOrder_Dishes_TDAL.GetListBy(u => u.DishesID == DisId).First();//一个菜品id一条菜品信息查菜品实际价格菜品分类id
            //                //Model.View_Order_DayReport TypeDayReport = base.DBSession.IView_Order_DayReportDAL.GetListBy(u => u.DishesID == DisId).First();//获取分类日结id
            //                //NewDishes_T.TypeDayReportID = TypeDayReport.TypeDayReportID;//
            //                //Order_Dishes.DelPackMon=200 ;//包装费

            //                //是否优惠1:优惠；0：正常
            //                if (Order_Dishes.DishesPay != double.Parse(DishesMon[i]))
            //                {
            //                    Model.Order_Dishes_T BT = new Model.Order_Dishes_T();
            //                    BT.DishesID = Order_Dishes.DishesID;
            //                    BT.DishesPay = double.Parse(DishesMon[i]);
            //                    if (tongji.Count == 0)
            //                    {
            //                        tongji.Add(BT);
            //                    }
            //                    else
            //                    {
            //                        List<Model.Order_Dishes_T> l = tongji.FindAll(u => u.DishesPay == double.Parse(DishesMon[i]) & u.DishesID == DisId);
            //                        if (l.Count == 0)
            //                        {
            //                            tongji.Add(BT);
            //                        }
            //                    }
            //                    NewDishes_T.IsDiscount = 1;

            //                }
            //                NewDishes_T.DelPackMon = Order_Dishes.DelPackMon * int.Parse(DishesNun[i]);//包装费
            //                NewDishes_T.FormPayType = (int)st.FormPayType;
            //                //NewDishes_T.FormPayType = "单位用户";
            //                NewDishes_T.DishesID = DisId;//菜品id
            //                NewDishes_T.Count = int.Parse(DishesNun[i]);//数量
            //                NewDishes_T.DishesMon = int.Parse(Order_Dishes.DishesMon.ToString());//菜品原价
            //                NewDishes_T.DishesPay = int.Parse(DishesMon[i]);//实价
            //                //原价金额=原价*数量
            //                NewDishes_T.TypeOriginal = int.Parse(Order_Dishes.DishesMon.ToString()) * int.Parse(DishesNun[i]);
            //                //实收=实价*数量
            //                NewDishes_T.TypeActual = (int.Parse(DishesMon[i]) * int.Parse(DishesNun[i]));
            //                NewDishes.Add(NewDishes_T);//把所有菜品分类，得菜品信息（菜品分类id、实际价格）
            //            }
            //        }
            //        List<Model.Order_Dishes_T> Dish = new List<Model.Order_Dishes_T>();
            //        if (string.IsNullOrEmpty(MerID))
            //        {
            //            Dish = base.DBSession.IOrder_Dishes_TDAL.GetListBy(u => u.DishesTypeState == 1);//获取商户菜品id


            //        }
            //        else
            //        {
            //            Dish = base.DBSession.IOrder_Dishes_TDAL.GetListBy(u => u.MerID == MerID & u.DishesTypeState == 1);//获取商户菜品id

            //        }
            //        //Model.Order_Mer_T mer = base.DBSession.IOrder_Mer_TDAL.GetListBy(u => u.MerID == MerID).First();

            //        foreach (var it in Dish)//轮询该商户菜品id
            //        {
            //            List<Model.Order_Dishes_T> bb = tongji.FindAll(u => u.DishesID == it.DishesID);
            //            Model.Allreport_T ls = new Model.Allreport_T();
            //            Model.Allreport_T ls1 = new Model.Allreport_T();
            //            Model.View_Order_DayReport Dishes = new Model.View_Order_DayReport();
            //            Model.View_Order_DayReport Dishes_IsDiscount = new Model.View_Order_DayReport();//优惠
            //            Model.View_Order_DayReport Dishes_IsDiscount1 = new Model.View_Order_DayReport();//优惠
            //            Model.View_Order_DayReport Dishes_IsDiscount2 = new Model.View_Order_DayReport();//优惠
            //            Model.View_Order_DayReport Dishes_IsDiscount3 = new Model.View_Order_DayReport();//优惠
            //            double delmon3 = 0;
            //            Model.View_Order_DayReport Dishes_IsDiscount4 = new Model.View_Order_DayReport();//优惠
            //            double delmon4 = 0;
            //            double delmon2 = 0;
            //            double delmon = 0;
            //            double delmon1 = 0;
            //            Model.View_Order_DayReport Dishes1 = new Model.View_Order_DayReport();
            //            //List<Model.View_Order_DayReport> DayReport = base.DBSession.IView_Order_DayReportDAL.GetListBy(u => u.MerID == MerID&u.DishesID==it.DishesID);

            //            List<Model.Order_DishesType_T> bk = base.DBSession.IOrder_DishesType_TDAL.GetListBy(u => u.DishesTypeID == it.DishesTypeID);//取菜名
            //            Model.Order_DishesType_T DishesType_Name = new Model.Order_DishesType_T();

            //            List<Model.Order_Mer_T> mer1 = new List<Model.Order_Mer_T>();

            //            if (bk.Count != 0)
            //            {
            //                DishesType_Name = bk[0];
            //               // mer1 = base.DBSession.IOrder_Mer_TDAL.GetListBy(u => u.MerID == DishesType_Name.MerID & u.MerState == 1);

            //            }
            //            Model.Order_Mer_T mer = new Model.Order_Mer_T();
            //            if (mer1.Count != 0)
            //            {
            //                mer = mer1[0];
            //            }
            //            for (int i = 0; i < NewDishes.Count; i++)
            //            {
            //                if (it.DishesID == NewDishes[i].DishesID & NewDishes[i].IsDiscount == 0)
            //                {
            //                    //Dishes.TypeDayReportID = NewDishes[i].TypeDayReportID;
            //                    Dishes.MerID = DishesType_Name.MerID;
            //                    Dishes.MerName = mer.MerName;
            //                    Dishes.DishesTypeName = DishesType_Name.DishesTypeName;
            //                    Dishes.DishesTypeID = DishesType_Name.DishesTypeID;
            //                    Dishes.DishesID = NewDishes[i].DishesID;
            //                    Dishes.DishesNmae = it.DishesNmae;
            //                    Dishes.DishesMon = NewDishes[i].DishesMon;
            //                    Dishes.DishesPay = NewDishes[i].DishesPay;
            //                    Dishes.DishesCount += NewDishes[i].Count;
            //                    Dishes.DishesOriginal += NewDishes[i].TypeOriginal;
            //                    Dishes.DishesActual += NewDishes[i].TypeActual;
            //                    ls.DelPackMon += NewDishes[i].DelPackMon;
            //                }


            //                if (it.DishesID == NewDishes[i].DishesID & NewDishes[i].IsDiscount == 1)
            //                { 
            //                    if (bb.Count >= 1 & bb.Count <= 5)
            //                    {
            //                        if (bb[0].DishesPay == NewDishes[i].DishesPay)
            //                        {
            //                            Dishes_IsDiscount.MerID = DishesType_Name.MerID;
            //                            Dishes_IsDiscount.MerName = mer.MerName;
            //                            Dishes_IsDiscount.DishesTypeName = DishesType_Name.DishesTypeName;
            //                            Dishes_IsDiscount.DishesTypeID = DishesType_Name.DishesTypeID;
            //                            Dishes_IsDiscount.DishesID = NewDishes[i].DishesID;
            //                            Dishes_IsDiscount.DishesNmae = it.DishesNmae + "(优惠)";
            //                            Dishes_IsDiscount.DishesMon = NewDishes[i].DishesMon;
            //                            Dishes_IsDiscount.DishesPay = NewDishes[i].DishesPay;
            //                            Dishes_IsDiscount.DishesCount += NewDishes[i].Count;
            //                            Dishes_IsDiscount.DishesOriginal += NewDishes[i].TypeOriginal;
            //                            Dishes_IsDiscount.DishesActual += NewDishes[i].TypeActual;
            //                            delmon1 += NewDishes[i].DelPackMon;

            //                        }
            //                        if (bb.Count >= 2)
            //                        {
            //                            if (bb[1].DishesPay == NewDishes[i].DishesPay)
            //                            {
            //                                Dishes_IsDiscount1.MerID = DishesType_Name.MerID;
            //                                Dishes_IsDiscount1.MerName = mer.MerName;
            //                                Dishes_IsDiscount1.DishesTypeName = DishesType_Name.DishesTypeName;
            //                                Dishes_IsDiscount1.DishesTypeID = DishesType_Name.DishesTypeID;
            //                                Dishes_IsDiscount1.DishesID = NewDishes[i].DishesID;
            //                                Dishes_IsDiscount1.DishesNmae = it.DishesNmae + "(优惠)";
            //                                Dishes_IsDiscount1.DishesMon = NewDishes[i].DishesMon;
            //                                Dishes_IsDiscount1.DishesPay = NewDishes[i].DishesPay;
            //                                Dishes_IsDiscount1.DishesCount += NewDishes[i].Count;
            //                                Dishes_IsDiscount1.DishesOriginal += NewDishes[i].TypeOriginal;
            //                                Dishes_IsDiscount1.DishesActual += NewDishes[i].TypeActual;
            //                                delmon += NewDishes[i].DelPackMon;
            //                            }
            //                        }
            //                        if (bb.Count >= 3)
            //                        {
            //                            if (bb[2].DishesPay == NewDishes[i].DishesPay)
            //                            {
            //                                Dishes_IsDiscount2.MerID = DishesType_Name.MerID;
            //                                Dishes_IsDiscount2.MerName = mer.MerName;
            //                                Dishes_IsDiscount2.DishesTypeName = DishesType_Name.DishesTypeName;
            //                                Dishes_IsDiscount2.DishesTypeID = DishesType_Name.DishesTypeID;
            //                                Dishes_IsDiscount2.DishesID = NewDishes[i].DishesID;
            //                                Dishes_IsDiscount2.DishesNmae = it.DishesNmae + "(优惠)";
            //                                Dishes_IsDiscount2.DishesMon = NewDishes[i].DishesMon;
            //                                Dishes_IsDiscount2.DishesPay = NewDishes[i].DishesPay;
            //                                Dishes_IsDiscount2.DishesCount += NewDishes[i].Count;
            //                                Dishes_IsDiscount2.DishesOriginal += NewDishes[i].TypeOriginal;
            //                                Dishes_IsDiscount2.DishesActual += NewDishes[i].TypeActual;
            //                                delmon2 += NewDishes[i].DelPackMon;

            //                            }


            //                        }
            //                        if (bb.Count >= 4)
            //                        {
            //                            if (bb[3].DishesPay == NewDishes[i].DishesPay)
            //                            {
            //                                Dishes_IsDiscount3.MerID = DishesType_Name.MerID;
            //                                Dishes_IsDiscount2.MerName = mer.MerName;
            //                                Dishes_IsDiscount3.DishesTypeName = DishesType_Name.DishesTypeName;
            //                                Dishes_IsDiscount3.DishesTypeID = DishesType_Name.DishesTypeID;
            //                                Dishes_IsDiscount3.DishesID = NewDishes[i].DishesID;
            //                                Dishes_IsDiscount3.DishesNmae = it.DishesNmae + "(优惠)";
            //                                Dishes_IsDiscount3.DishesMon = NewDishes[i].DishesMon;
            //                                Dishes_IsDiscount3.DishesPay = NewDishes[i].DishesPay;
            //                                Dishes_IsDiscount3.DishesCount += NewDishes[i].Count;
            //                                Dishes_IsDiscount3.DishesOriginal += NewDishes[i].TypeOriginal;
            //                                Dishes_IsDiscount3.DishesActual += NewDishes[i].TypeActual;
            //                                delmon3 += NewDishes[i].DelPackMon;

            //                            }


            //                        }
            //                        if (bb.Count >= 5)
            //                        {
            //                            if (bb[4].DishesPay == NewDishes[i].DishesPay)
            //                            {
            //                                Dishes_IsDiscount4.MerID = DishesType_Name.MerID;
            //                                Dishes_IsDiscount2.MerName = mer.MerName;
            //                                Dishes_IsDiscount4.DishesTypeName = DishesType_Name.DishesTypeName;
            //                                Dishes_IsDiscount4.DishesTypeID = DishesType_Name.DishesTypeID;
            //                                Dishes_IsDiscount4.DishesID = NewDishes[i].DishesID;
            //                                Dishes_IsDiscount4.DishesNmae = it.DishesNmae + "(优惠)";
            //                                Dishes_IsDiscount4.DishesMon = NewDishes[i].DishesMon;
            //                                Dishes_IsDiscount4.DishesPay = NewDishes[i].DishesPay;
            //                                Dishes_IsDiscount4.DishesCount += NewDishes[i].Count;
            //                                Dishes_IsDiscount4.DishesOriginal += NewDishes[i].TypeOriginal;
            //                                Dishes_IsDiscount4.DishesActual += NewDishes[i].TypeActual;
            //                                delmon4 += NewDishes[i].DelPackMon;

            //                            }


            //                        }

            //                    }
            //                    //if(bb.Count ==1)  {
            //                    ////Dishes.TypeDayReportID = NewDishes[i].TypeDayReportID;
            //                    //Dishes_IsDiscount.MerID = MerID;
            //                    ////Dishes_IsDiscount.MerName = mer.MerName;
            //                    //Dishes_IsDiscount.DishesTypeName = DishesType_Name.DishesTypeName;
            //                    //Dishes_IsDiscount.DishesTypeID = DishesType_Name.DishesTypeID;
            //                    //Dishes_IsDiscount.DishesID = NewDishes[i].DishesID;
            //                    //Dishes_IsDiscount.DishesNmae = it.DishesNmae + "(优惠)";
            //                    //Dishes_IsDiscount.DishesMon = NewDishes[i].DishesMon;
            //                    //Dishes_IsDiscount.DishesPay = NewDishes[i].DishesPay;
            //                    //Dishes_IsDiscount.DishesCount += NewDishes[i].Count;
            //                    //Dishes_IsDiscount.DishesOriginal += NewDishes[i].TypeOriginal;
            //                    //Dishes_IsDiscount.DishesActual += NewDishes[i].TypeActual;
            //                    //delmon1 += NewDishes[i].DelPackMon;
            //                    //}
            //                }

            //            }
            //            Model.Allreport_T report1 = new Model.Allreport_T();
            //            if (Dishes.DishesID != null & Dishes.DishesID != "")
            //            {
            //                report1.DelPackMon = ls.DelPackMon / 100;
            //                report1.Order_DayReport = Dishes;
            //                list.Add(report1);
            //            }
            //            Model.Allreport_T os1 = new Model.Allreport_T();
            //            Model.Allreport_T os2 = new Model.Allreport_T();
            //            Model.Allreport_T os3 = new Model.Allreport_T();
            //            Model.Allreport_T os4 = new Model.Allreport_T();
            //            Model.Allreport_T os5 = new Model.Allreport_T();
            //            if (Dishes_IsDiscount.DishesID != null & Dishes_IsDiscount.DishesID != "")
            //            {
            //                os1.IsDiscount = 1;
            //                os1.DelPackMon = delmon1 / 100;
            //                os1.Order_DayReport = Dishes_IsDiscount;
            //                list.Add(os1);
            //                //mo.Add(Dishes1);
            //            }
            //            if (Dishes_IsDiscount1.DishesID != null & Dishes_IsDiscount1.DishesID != "")
            //            {
            //                os2.IsDiscount = 1;
            //                os2.DelPackMon = delmon / 100;
            //                os2.Order_DayReport = Dishes_IsDiscount1;
            //                list.Add(os2);
            //                //mo.Add(Dishes1);
            //            }

            //            if (Dishes_IsDiscount2.DishesID != null & Dishes_IsDiscount2.DishesID != "")
            //            {
            //                os3.IsDiscount = 1;
            //                os3.DelPackMon = delmon2 / 100;
            //                os3.Order_DayReport = Dishes_IsDiscount2;
            //                list.Add(os3);
            //                //mo.Add(Dishes1);
            //            }
            //            if (Dishes_IsDiscount3.DishesID != null & Dishes_IsDiscount3.DishesID != "")
            //            {
            //                os4.IsDiscount = 1;
            //                os4.DelPackMon = delmon3 / 100;
            //                os4.Order_DayReport = Dishes_IsDiscount3;
            //                list.Add(os4);
            //                //mo.Add(Dishes1);
            //            }
            //            if (Dishes_IsDiscount4.DishesID != null & Dishes_IsDiscount4.DishesID != "")
            //            {
            //                os5.IsDiscount = 1;
            //                os5.DelPackMon = delmon4 / 100;
            //                os5.Order_DayReport = Dishes_IsDiscount4;
            //                list.Add(os5);
            //                //mo.Add(Dishes1);
            //            }
            //        }

            //    }
            //    #endregion

            //    if (list != null && list.Count != 0)
            //    {
            //        result.BS = "1";
            //        result.Msg = "查询成功";
            //        result.total = list.Count;
            //        result.rows = list;

            //    }
            //    else
            //    {
            //        result.BS = "0";
            //        result.Msg = "查询不到数据！";
            //    }

            //    return os.StringOfObject(result, RETID);
            //}
            //catch (Exception)
            //{
            //    result.BS = "-1";
            //    result.Msg = "查询失败！";
            //    return os.StringOfObject(result, RETID);
            //}

            //#endregion
        }

        //public class allreport{
        //    public double DelPackMon { get; set; }
        //    public Model.View_Order_DayReport Order_DayReport { get; set; }

        //}
    }
}
